package com.yunhe.util;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


public  class MyBatisUtil {
	
	static String resourse = "mybatis.xml";
	static SqlSession session = null;
	private static SqlSessionFactory factory = null;
	static{
		try {
			Reader reader = Resources.getResourceAsReader(resourse);
			factory = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	public static SqlSession getSession(){
		
		session = factory.openSession();
		return session;
	}
}
